package com.lollipop.programming.designpattern.proxy.cglib;


import lombok.extern.slf4j.Slf4j;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author Lollipop
 * @Version 1.0
 * @Date 2025/4/12 15:10
 * @Description Cglib动态代理处理器
 */
@Slf4j
public class CglibDynamicProxyHandler implements MethodInterceptor {
    private Object target;

    public CglibDynamicProxyHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        log.info("================ Cglib动态代理处理器 ================");
        log.info("目标方法执行前");
        Object result = methodProxy.invoke(target, objects);
        log.info("目标方法执行后");
        return result;
    }
}
